<?php
/*
	提现
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
defined('BY_JYA') or exit('error');
global $_RQ;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'get';
if($_RQ['op']=='get'){
	$member=pdo_get('core_members',array('id'=>$_SESSION['uid']));
	$daytime = mktime(0,0,0,date('m'),date('d'),date('Y'));
	$data['allmoney']=$this->getsum('store_commission',array('workerid'=>$this->workerid),'total_price');
	$data['commission_total']=$this->getsum('store_commission',array('workerid'=>$this->workerid),'money');
	$data['daifee']=$this->getsum('store_commission',array('status'=>1,'workerid'=>$this->workerid,'createtime >'=>$daytime),'money');
	$data['dayfee']=$this->getsum('store_commission',array('workerid'=>$this->workerid,'createtime >'=>$daytime),'total_price');
	$data['tixian']=$member['credit2'];
	$return['data']=$data;
	$return['member']=$member;
	$return['params']['type']=$_RQ['type']?:2;
	if($this->setting['withdrawtype']){
		$withdrawtype=array();
		$check=strstr($this->setting['withdrawtype'],'credit');
		if($check){
			$withdrawtype['credit']=$this->pay_types['credit'];
			$pay_type='credit';
		}
		$check=strstr($this->setting['withdrawtype'],'wechat');
		if($check){
			$withdrawtype['wechat']=$this->pay_types['wechat'];
			$pay_type=$pay_type?:'wechat';
		}
		$check=strstr($this->setting['withdrawtype'],'alipay');
		if($check){
			$withdrawtype['alipay']=$this->pay_types['alipay'];
			$pay_type=$pay_type?:'alipay';
		}
		$check=strstr($this->setting['withdrawtype'],'union');
		if($check){
			$withdrawtype['union']=$this->pay_types['union'];
			$pay_type=$pay_type?:'union';
		}
		$return['pay_types']=$withdrawtype;
	}else{
		$return['pay_types']=$this->pay_types;
		$pay_type='credit';
	}
	$return['post']=array('pay_type'=>$pay_type);
	set_html('title','我的业绩');
	exi($return);
}
if($_RQ['op']=='password'){
	$post=get_postdata();
	if(!$post['password']){
		exi('请输入支付密码！','erroe');
	}
	pdo_update('core_members',array('paypassword'=>$post['password']),array('id'=>$_SESSION['uid']));
	exi('设置成功！');
}
if($_RQ['op']=='feelist'){
	$pindex = max(1, intval($_RQ['page']));
	$psize = 15;
	$params=array('uniacid'=>$_SESSION['uniacid'],'workerid'=>$this->workerid);
	if($_RQ['type']){
		$params['type']=$_RQ['type'];
	}
    $orderby='createtime desc';
	$total='';
	$return['list']=$this->getslice('store_commission',$params,array($pindex,$psize),$total,$fields,'',$orderby);	
	foreach($return['list'] as &$v){
			$v['createtime']=date('Y-m-d H:i:s',$v['createtime']);
			$v['typetitle']=$this->commission_types[$v['type']];
			$v['statustitle']=$this->commission_status[$v['status']];
	}
	exi($return);
}
if($_RQ['op']=='set'){
	if($_RQ['postdata']){
		$post=get_postdata();
		$member_update=array(
			'downdata'=>ijson_encode($post['downdata']),
		);
		$this->pdo_update('member',$member_update,array('mid'=>$_SESSION['uid']));
		exi('操作成功！','','/store.manage.myfee/');
	}
	$item=$this->pdo_get('member',array('mid'=>$_SESSION['uid']));
	$item['downdata']=$item['downdata']?json_decode($item['downdata'],true):array('down'=>array(array('num'=>5)));
	$item['downdata']['down']=$item['downdata']['down']?:array(array('num'=>5));
	$return['item']=$item;
	exi($return);
}
//结算
if($_RQ['op']=='balance'){
	$post=get_postdata();
	$post['feetype']=$post['feetype']==1?$this->setting['bufee_type']:2;
	$this->model('store')->create_workerbalance($this->workerid,$post);
	exi('申请结算成功！','','/store.manage.myfee/');
}